{{define "content"}}
{{template "page_title" .}}
<div class="row">
    <div class="col-12">
        <form id="main" class="card" method="post">
            <div class="card-body">
                {{template "cmd_form" .}}
                <div class="row">
                    <div class="col-md-4">
                        <div class="mb-2">
                            <label class="form-label">计划配置</label>
                            <input name="spec" type="text" class="form-control" placeholder="请输入计划配置" value="">
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-4">
                        <div class="mb-2">
                            <label class="form-label">超时时间</label>
                            <input name="timeout" type="text" class="form-control" placeholder="请输入超时时间" value="-1">
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="mb-2">
                            <label class="form-label">是否开启监控</label>
                            <label class="form-check form-switch">
                                <input name="is_monitor" class="form-check-input" type="checkbox">
                            </label>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card-footer">
                <button type="submit" class="btn btn-primary">提交</button>
                <a href="/job/list" class="btn btn-danger ml-2">返回</a>
            </div>
        </form>
    </div>
</div>
{{end}}
{{define "script"}}
<script type="text/javascript">
    $(document).ready(function () {
        var out_base_dir = "{{.OutBaseDir}}";
        $('#group_id').selectize({});
        $('#agent_id').selectize({});
        $("#name").on("keyup", function (event) {
            var name = $("#name").val();
            if (name) {
                $("#std_out").val(out_base_dir + name + "_std_out.log");
                $("#std_err").val(out_base_dir + name + "_std_err.log");
            } else {
                $("#std_out").val(out_base_dir);
                $("#std_err").val(out_base_dir);
            }
        });
        $("#main").on("submit", function (event) {
            $('#main').ajaxSubmit({
                url: "/job/create",
                dataType: "json",
                timeout: 60000,
                success: function (data) {
                    if (data.code == 200) {
                        window.location.href = "/job/list";
                    } else {
                        alert(data.message);
                    }
                }
            })
            return false;
        });
    });
</script>
{{end}}